<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE HTML>
<html lang="zh-CN">
    <head>
    <meta charset="utf-8">
    <%@ include file="/WEB-INF/views/include/head.jsp"%> 
    <link rel="stylesheet" href="${ctxStatic}/css/layerSm.css">
        <script type="text/javascript">
        var windowH = window.innerHeight
                            ||document.documentElement.clientHeight
                            ||document.body.clientHeight
                    $('.middle').css('height',windowH - 40);
      //获取 iframe 数量 
		var frLength = window.parent.frames.length;
		//父画面下标 
		var parentIndex = frLength-2;
        $(document).ready(function(){
            
            // 下拉选框带搜索功能
            $("#propertyUnitCd").select2();
           });
              //子项目保存
              var saveForm={
                    s:null,
                        t:null,
                        save:function(s,t){
                            $(t).attr("disabled",true);
                            this.s=s;
                            this.t=t;
                            formUnFormat($("#inputForm"));
                     /*  if($('#subPropertyCode').val().trim() == $('#propertyValue').val().trim()){
                        // 定制子项项目值重复，请重新输入！
                           layer.msg('<spring:message code="fitpropertyPropertyValueAndCodeNotRepetition"/>', {time:2000}); 
                           $(saveForm.t).attr("disabled",false);
                           return;
                      } */
                      if($('#subPropertyCd').val().trim() == $('#propertyValue').val().trim()){
                          // 定制子项项目值重复，请重新输入！
                             layer.msg('<spring:message code="fitpropertyPropertyValueAndCodeNotRepetition"/>', {time:2000}); 
                             $(saveForm.t).attr("disabled",false);
                             return;
                        }
                      // 子项值是否重复
/*                      var result = window.parent.frames[parentIndex].isSubPropertyValueRepeate($('#propertyValue').val(),$('#delIndex').val());
                      if (result == true) {

                          // 定制子项项目值重复，请重新输入！
                          layer.msg('<spring:message code="subPropertyValeRepetition"/>', {time:2000});
                          $(saveForm.t).attr("disabled",false);
                          return;

                      }*/
                      // 表单验证
                      $("#inputForm").validate({
                          submitHandler: function() {
                              // 格式化，去除逗号
                              formUnFormat($("#inputForm"));
                              // 从表单中获取数据
                              var params = $("#inputForm").serialize();
                              // 调用后台保存子项方法
                              $.post("${ctx}/custom/fitproperty/saveSub", params, function(result) {
                                  
                                  // 保存未成功
                                  if (result == "false") {
                                      // 表单重置
                                      $("#inputForm")[0].reset();
                                      $(saveForm.t).attr("disabled",false);
                                  // 保存成功
                                  } else {
                                      if(saveForm.s==1){
                                          
                                          // 调取父页面方法
                                          window.parent.frames[parentIndex].addPropertyValue();
                                          
                                          // 表单重置
                                          $("#inputForm")[0].reset();  
                                          // 下拉选框带搜索功能
                                          $("#propertyUnitCd").select2();
                                          $(saveForm.t).attr("disabled",false);
                                      }else{
                                          // 调取父页面方法
                                          window.parent.frames[parentIndex].addPropertyValue();
                                          
                                          // 关闭页面
                                          closeWin(); 
                                       }
                                     
                                  }
                              }, 'json');
                              },
                              rules: {
                                  // 后台验证重名方法
                                  propertyValue: {remote: "${ctx}/custom/fitproperty/checkPropertyValue?oldPropertyValue=" +$("#oldPropertyValue").val() },
                              },
                              messages: {
                                  //项目值已存在
                                  propertyValue: {remote: '<spring:message code="fitpropertyPropertyValue_exist"/>'},
                              },
                              fail: function(element,e) {  
                                    $(saveForm.t).attr("disabled",false);
                                }
                      });
                      
                      //表单提交
                      $("#inputForm").submit(); 
                  } 
              }
        function chose(obj) {
            if (obj.checked) {
                $("#fitUseTypeCd").val("FIT_USE_TYPE-FIT_TYPE_20");
                $("#propertyInFrom").attr("disabled",false);
                $("#propertyInFrom").val($("#propertyInFromHidden").val());
                $("#propertyInFrom").removeClass("inputBackolor");

                $("#propertyInTo").attr("disabled",false);
                $("#propertyInTo").val($("#propertyInToHidden").val());
                $("#propertyInTo").removeClass("inputBackolor");

                $("#propertyOutFrom").attr("disabled",false);
                $("#propertyOutFrom").val($("#propertyOutFromHidden").val());
                $("#propertyOutFrom").removeClass("inputBackolor");

                $("#propertyOutTo").attr("disabled",false);
                $("#propertyOutTo").val($("#propertyOutToHidden").val());
                $("#propertyOutTo").removeClass("inputBackolor");
            } else {
                $("#propertyInFrom").attr("disabled",true);
                $("#propertyInFrom").addClass("inputBackolor");
                $("#propertyInFrom").val("");

                $("#propertyInTo").attr("disabled",true);
                $("#propertyInTo").addClass("inputBackolor");
                $("#propertyInTo").val("");

                $("#propertyOutFrom").attr("disabled",true);
                $("#propertyOutFrom").addClass("inputBackolor");
                $("#propertyOutFrom").val("");

                $("#propertyOutTo").attr("disabled",true);
                $("#propertyOutTo").addClass("inputBackolor");
                $("#propertyOutTo").val("");

                $("# ").val("");
            }
        }
        </script>
        <style>
            .inputBackolor{
                background-color: #7461614d;
            }
        </style>

    </head>
    <body>
        <!--头部-->
        <div class="layerHeader clearfix">
            <!-- 新建子项目 -->
            <c:choose>
                <c:when test="${not empty fitproperty.propertyValue}"><spring:message code="fitproperty_editsubfitproperty"/></c:when>
                <c:otherwise><spring:message code="fitproperty_createsubfitproperty"/></c:otherwise>
            </c:choose>
            <div class="headerButton clearfix">
                <!-- 取消 -->
                <button type="button" onclick="closeWin()"><spring:message code="company_edit_cancle"/></button>
                <shiro:hasPermission name="custom:fitproperty:edit">
                    <!-- 子项目保存 -->
                    <button type="button"  style="margin:0 auto;" onclick="saveForm.save(0,this)"><spring:message code="fitproperty_save"/></button>
                    <!-- 子项目保存并继续 -->
                    <button type="button"  onclick="saveForm.save(1,this)"><spring:message code="fitproperty_saveAndcontinue"/></button>
                </shiro:hasPermission>
            </div>

        </div>
        <form id="inputForm" method="post">
        <c:set value="<%=ResourcesUtil.getConfig(\"fitPropertyUnit\")%>" var="projectUnits" />
            <input type="hidden"  id="delIndex" name="delIndex" value="${fitproperty.delIndex}">
<%--             <input type="hidden" id="subPropertyCode" name="subPropertyCode" value="${fitproperty.propertyCd}"/> --%>
            <input type="hidden" id="subPropertyCd" name="subPropertyCd" value="${fitproperty.propertyCd}"/>
            <input type="hidden" id="oldPropertyValue" name="oldPropertyValue" value="${fitproperty.oldPropertyValue}"/>

            <input type="hidden" id="propertyInFromHidden" value="${fitproperty.propertyInFrom}"/>
            <input type="hidden" id="propertyInToHidden" value="${fitproperty.propertyInTo}"/>
            <input type="hidden" id="propertyOutFromHidden" value="${fitproperty.propertyOutFrom}"/>
            <input type="hidden" id="propertyOutToHidden" value="${fitproperty.propertyOutTo}"/>
           <%-- <input type="hidden" id="fitUseTypeCd" name="fitUseTypeCd"/>--%>
            <div class="smOrderBox">
                        <div class ="clearfix">
                            <div class="col-50 items clearfix">
                            <!-- 子项目代码 -->
                             <p class="tit"><spring:message code="fitproperty_Cd"/></p>
                             <p class="fashion">${fitproperty.propertyCd}</p>
                            </div>
                        </div>
                        <div class="clearfix">
                            <div class="col-50 items clearfix haveToBox">
                                <!-- 子项目值 -->
                                <p class="tit"><spring:message code="fitproperty_value"/></p>
                                <c:choose>
                                    <c:when test="${not empty fitproperty.propertyValue}"><p>${fitproperty.propertyValue}</p></c:when>
                                    <c:otherwise>
                                        <input type="text"  id="propertyValue" name="propertyValue" value="${fitproperty.propertyValue}"  maxlength="22" data-msg-required="<spring:message code="fitproperty_pleaseInputValue"/>"  data-rule-lettersnumbers="true"  data-msg-lettersnumbers="<spring:message code="fitproperty_pleaseInputValue"/>" data-rule-required="true" class="form-control fam">
                                        <p class="haveTo">*</p>
                                    </c:otherwise>
                                </c:choose>
                            </div>
                            <div class="col-50 items clearfix haveToBox">
                                <!-- 子项目单位 -->
                                <p class="tit"><spring:message code="fitproperty_unit"/></p>
                                 <select class="" style="width: 150px" id="propertyUnitCd" name="propertyUnitCd" data-rule-required="true" data-msg-required="<spring:message code="fitproperty_pleaseChoosedUnit"/>" >
                                        <option value=""><spring:message code="fitproperty_pleaseChoosed"/></option>
                                    <c:forEach items="${fns:getDictList(projectUnits)}"   var="itemUnit">
                                         <option  <c:if test="${fn:split(fitproperty.propertyUnitCd,'-')[1] eq itemUnit.itemValue}">selected="selected"</c:if> value="${itemUnit.itemCode}-${itemUnit.itemValue}" >
                                     ${itemUnit.itemName}
                                 </option>
                             </c:forEach>
                         </select>
                                <p class="haveTo">*</p>
                            </div>
                         </div>
                        <div class="clearfix">
                            <div class="col-50 items clearfix haveToBox">
                                <!-- 子项目中文名称 -->
                                <p class="tit"><spring:message code="fitproperty_Cn"/></p>
                                <input type="text"  id="propertyNameCn" name="propertyNameCn" value="${fitproperty.propertyNameCn }"  maxlength="50" data-msg-required="<spring:message code="fitproperty_pleaseInputCn"/>" data-rule-required="true" class="form-control fam">
                                <p class="haveTo">*</p>
                             </div>
                            <div class="col-50 items clearfix haveToBox">
                                <!-- 子项目英文名称 -->
                                <p class="tit"><spring:message code="fitproperty_En"/></p>
                                <input type="text" id="propertyNameEn" name="propertyNameEn" value="${fitproperty.propertyNameEn }"  maxlength="50" data-msg-required="<spring:message code="fitproperty_pleaseInputEn"/>" data-rule-required="true"  class="form-control fam">
                                <p class="haveTo">*</p>
                             </div>
                        </div>
                        <div class="clearfix">
                            <div class="col-50 items clearfix haveToBox">
                                <!-- 子项目日文名称 -->
                                <p class="tit"><spring:message code="fitproperty_Jp"/></p>
                                <input type="text"  id="propertyNameJp" name="propertyNameJp" value="${fitproperty.propertyNameJp }"  maxlength="50" data-msg-required="<spring:message code="fitproperty_pleaseInputJp"/>" data-rule-required="true" class="form-control fam">
                                <p class="haveTo">*</p>
                            </div>
                         </div>
                        <div class="clearfix">
                        <div class="col-50 items clearfix haveToBox labelBox">
                            <p style="float: left;width: 85px"><spring:message code="fitproperty_adjust_item"/></p>
                            <input name="fitUseTypeCd" id="fitUseTypeCd" type="checkbox"
                            <c:if test="${fitproperty.fitUseTypeCd eq 'FIT_USE_TYPE-FIT_TYPE_20'}">checked='checked'</c:if>
                            <c:if test="${ empty fitproperty.propertyValue}">checked='checked' value="FIT_USE_TYPE-FIT_TYPE_20"</c:if>
                                          onclick="chose(this)" style="float:left;width:30px;height: 28px" >
                            </label>
                            </div>
                            <div class="col-50 items clearfix haveToBox">&nbsp;</div>
                        </div>
                        <div class="clearfix">
                        <div class="col-50 items clearfix">
                            <!-- 子项目增加范围 -->
                            <p class="tit"><spring:message code="fitproperty_additionalRanges"/></p>
                            <input type="text"  id="propertyInFrom" name="propertyInFrom" value="${fitproperty.propertyInFrom }" data-rule-nonnegativeInteger="true"  data-msg-nonnegativeInteger="<spring:message code="Please_enter_a_positive_integer"/>"  data-rule-maxlength="9"   data-msg-maxlength="<spring:message code="fitproperty_please_input_rightvalue"/>" >
                           </div>
                        <div class="col-50 items clearfix haveToBox">
                            <p class="haveTo">~</p>
                            <input type="text"  id="propertyInTo" name="propertyInTo" value="${fitproperty.propertyInTo}" data-rule-nonnegativeInteger="true"  data-msg-nonnegativeInteger="<spring:message code="Please_enter_a_positive_integer"/>"  >
                        </div>
                        </div>
                        <div class="clearfix">
                        <div class=" col-50 items clearfix">
                            <!-- 子项目缩减范围 -->
                            <p class="tit"><spring:message code="fitproperty_rangeReduction"/></p>
                            <input type="text" id="propertyOutFrom" name="propertyOutFrom" value="${fitproperty.propertyOutFrom }" data-rule-nonnegativeInteger="true"  data-msg-nonnegativeInteger="<spring:message code="Please_enter_a_positive_integer"/>" data-rule-maxlength="5"   data-msg-maxlength="<spring:message code="fitproperty_please_input_rightvalue"/>" >
                        </div>
                        <div class=" col-50 items clearfix haveToBox">
                                <p class="haveTo">~</p>
                                <input type="text" id="propertyOutTo" name="propertyOutTo" value="${fitproperty.propertyOutTo}" data-rule-nonnegativeInteger="true"  data-msg-nonnegativeInteger="<spring:message code="Please_enter_a_positive_integer"/>" data-rule-maxlength="5"   data-msg-maxlength="<spring:message code="fitproperty_please_input_rightvalue"/>"  >
                        </div>
                    </div>
                        <div class="clearfix">
                            <div class="col-50 items clearfix">
                                <!-- 子项目状态 -->
                                <p class="tit"><spring:message code="fitproperty_state"/></p>
                                <div class="labelBox">
                                <label class="lbst">
                                    <input type="radio" checked='checked' name="enableFlag"  value="1" <c:if test="${fitproperty.enableFlag eq 1}">checked='checked'</c:if> class="rast"/><spring:message code="fitproperty_enable"/>
                                </label>
                                <label class="lbst">
                                    <input type="radio" id="enableFlag_check" name="enableFlag" value="0" <c:if test="${fitproperty.enableFlag eq 0}">checked='checked'</c:if> class="rast" /><spring:message code="fitproperty_disable"/>
                                </label>
                            </div>
                            </div>
                    </div>
                        <div class="clearfix">
                            <div class="col-50 items  clearfix">
                                <!-- 子项目描述 -->
                                <p style="float: left;width: 100px"><spring:message code="fitproperty_remarks"/>
                                    <span >(0/100)</span>
                                </p>
                                <div class="">
                                    <textarea  name="remarks" value="${fitproperty.remarks }"  maxlength="100">${fitproperty.remarks }</textarea>
                                </div>
                            </div>
                         </div>
                </div>
        </form>
    </body>
</html>